import os
base_path="D:/PythonProject1"
def hash_file_dir(hash_value):
    global  base_path
    hash_value = format(hash_value, 'x')

    hash_dir=[hash_value[i*2:(i+1)*2]for i in range(2)]
    file_name =hash_value[4:]

    return os.path.join(*hash_dir) ,file_name
def record_hash(content,hash_value):

    global base_path
    hash_dir,file_name=hash_file_dir(hash_value)

    hash_rel_dir=os.path.join(base_path ,hash_dir )
    file_rel_path=os.path.join(hash_rel_dir ,file_name )
    os.makedirs(hash_rel_dir  ,exist_ok= True)

    with open (file_rel_path ,'wb')as f:

        f.write(content)

def hash_value_exist(hash_value):

    global base_path
    hash_dir, file_name = hash_file_dir(hash_value)
    hash_rel_dir = os.path.join(base_path, *hash_dir)
    file_rel_path = os.path.join(hash_rel_dir, file_name)
    return os.path.exists(file_rel_path )